<template>
  <div>
    <div class="user-header">
      <div class="user-header-img">
        <el-avatar shape="square" :size="150" :src="form.avatar" v-if="form && $isNotEmpty(form.avatar)"/>
        <img src="@/assets/images/no_pic.png" alt="" v-else>
      </div>
      <div class="user-header-info">
        <div class="user-header-info-name">
          <p class="user-header-info-name-l">
            {{ form ? form.nickName : '' }}
            <em v-if="form && form.status=='0'">
<!--              <dict-tag v-if="form" :options="dict.type.sys_work_type" :value="form.type"/>-->
              在职
            </em>
            <em v-if="form && form.status=='1'" class="leaveWork">
              离职
            </em>
          </p>
          <div class="user-btn-status" v-if="form && form.status=='0'">
<!--            <span class="btn-user-r el-icon-sort" @click="handleViewTeam(1)">调动驻点</span>-->
            <span class="btn-user-r el-icon-document-delete" @click="handleViewTeam(2)">离职</span>
          </div>
        </div>
        <p class="user-header-info-address">
          <span class="name-title">
            归属组织
          </span>
          <span>
<!--            <em>{{ form ? form.dept.deptName : '' }}</em>/ <em>队员</em>-->
            {{ form ? form.dept.deptName : '' }}
          </span>
        </p>
        <div class="user-header-info-call">
          <div class="user-header-info-call-p">
            <p><span class="name-title">联系电话</span>{{ form ? form.phonenumber : '' }}</p>
            <p><span class="name-title">身份证号</span>{{ form ? form.idNumber : '' }}</p>
          </div>
          <div class="user-header-info-call-r">
            <p class="user-header-info-call-r-title">当前执勤驻点数</p>
            <div class="user-header-info-call-r-work">
              <p>0个主岗</p>
              <p>0个兼岗</p>
            </div>
          </div>
          <!--          <div class="user-header-info-call-r">-->
          <!--            <p class="user-header-info-call-r-title">当前出勤状态</p>-->
          <!--            <div class="user-header-info-call-r-work">-->
          <!--              <p>休息中</p>-->
          <!--            </div>-->
          <!--          </div>-->
        </div>
      </div>
    </div>
    <div class="user-table">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="个人档案" name="userInfo"></el-tab-pane>
        <el-tab-pane label="执勤点" name="pointAddress"></el-tab-pane>
        <el-tab-pane label="审批记录" name="approvalLog"></el-tab-pane>
        <el-tab-pane label="装备资产" name="property"></el-tab-pane>
      </el-tabs>
      <component :is="activeName" :form="form" :paramId="paramId" @getInit="handleEditUpdate"/>
    </div>
  </div>
</template>

<script>
import userInfo from "./components/userInfo";
import pointAddress from "./components/pointAddress";
import approvalLog from "./components/approvalLog";
import property from "./components/property";
import {getUser, updateUserEdit} from '@/api/system/user'
import {getInfoNew} from "@/api/login";

export default {
  dicts: ['sys_work_type'],
  name: "detail",
  components: {
    userInfo,
    pointAddress,
    approvalLog,
    property
  },
  data() {
    return {
      activeName: 'userInfo',
      form: null,
      paramId: 0
    };
  },
  created() {
    this.paramId = this.$route.params && this.$route.params.userId;
    this.handleEditUpdate()
  },
  methods: {
    handleViewTeam(option) {
      // this.$message.error('功能开发中')
      let that =this
      if (option == 2) {
        console.log('00000000iii', this.paramId)
        this.$modal.confirm('确认该保安离职，是否继续？').then(function () {
          return updateUserEdit({userId: that.paramId, status: 1,userName: that.form.userName});
        }).then(() => {
          this.handleEditUpdate();
          this.$modal.msgSuccess("操作成功");
        }).catch(() => {
          console.log('信息')
        });
      }
    },
    handleEditUpdate() {
      getInfoNew(this.paramId).then(response => {
        response.data.type = response.data.type.toString()
        this.form = response.data;
      });
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
  }
}
</script>

<style scoped>
.user-header {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 10px;
}

.user-header {
  display: flex;
}

.user-header-img {
  margin-right: 40px;
}

.user-header-img img {
  width: 186px;
}

.user-header-info {
  flex: 1;
}

.user-header-info p {
  margin: 0;
}

.user-header-info-name {
  font-size: 18px;
  font-weight: 500;
  display: flex;
  margin-bottom: 10px !important;
  align-items: center;
}

.user-header-info-name-l {
  flex: 1;
  display: flex;
}
.user-header-info-name em.leaveWork{
  background: red;
}
.user-header-info-name em {
  font-size: 12px;
  background: green;
  color: #fff;
  font-style: normal;
  margin-left: 10px;
  height: 22px;
  line-height: 22px;
  width: 50px;
  text-align: center;
  display: block;
  border-radius: 11px;
}

.user-header-info-address {
  font-size: 12px;
}

.user-header-info-address span {
  color: rgba(0, 0, 0, .3);
}

.user-header-info-address em {
  color: #ffba00;
  font-style: normal;
}

.name-title {
  margin-right: 20px;
}

.user-header-info-call {
  margin-top: 30px;
  border-top: 1px dashed #f4f4f4;
  width: 100%;
  padding-top: 20px;
  display: flex;
  font-size: 12px;
}

.user-header-info-call-p {
  flex: 1;
  border-right: 1px solid #f4f4f4;
}

.user-header-info-call-p p {
  margin-bottom: 10px;
}

.user-header-info-call-p span {
  color: rgba(0, 0, 0, .3);
}

.user-header-info-call-r {
  width: 130px;
  border-right: 1px solid #f4f4f4;
  padding: 0 20px;
}

.user-header-info-call-r-title {
  margin-bottom: 10px !important;
  color: rgba(0, 0, 0, .3);
}

.user-header-info-call-r-work {
  font-size: 14px;
}

.user-table {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
}

.user-btn-status {
  border: 1px solid #ddd;
  font-size: 12px;
  display: flex;
  align-items: center;
  border-radius: 15px;
  overflow: hidden;
}

.user-btn-status span {
  cursor: pointer;
  padding: 0 20px;
  height: 30px;
  display: block;
  line-height: 30px;
}

.user-btn-status span:first-child {
  border-right: 1px solid #ddd;
}

.user-btn-status span:hover {
  background: #f8f8f8;
}
</style>
